package com.neusoft.race.sys.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neusoft.utils.page.PageUtils;
import com.neusoft.utils.web.RequestUtils;
import com.neusoft.utils.web.Result;

import com.neusoft.race.sys.bean.SysDict;
import com.neusoft.race.sys.service.ISysDictService;


@Controller
@RequestMapping("/sysDict")
public class SysDictController {
	@Resource
	private ISysDictService sysDictService;

	

	@RequestMapping("/queryById")
	@ResponseBody
	public SysDict queryById(@RequestParam("id")String id){
		return sysDictService.queryById(id);
	}
	@RequestMapping("/queryPage")
	@ResponseBody
	public Page<SysDict> query(Integer page,Integer size,HttpServletRequest request,HttpServletResponse response){
		Pageable pageable = PageUtils.initPage(page, size);
		Map<String, Object> param =RequestUtils.getQueryParams(request);
		return sysDictService.queryPage(param, pageable);
	}
	@RequestMapping("/delete")
	@ResponseBody
	public Result deleteById(@RequestParam("id")String id){
		int result=sysDictService.deleteById(id);
		if(result==0){
			return new Result().setStatusFail().setMsg("删除失败");
		}
		return new Result().setMsg("删除成功");
	}
	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public Result saveOrUpdate(SysDict sysDict,HttpServletRequest request,HttpServletResponse response){
		if(null==sysDict){
			return new Result().setStatusFail().setMsg("请传入数据");
		}
		String msg="增加";
		if(null!=sysDict.getId()){
			msg="修改";
		}
		int result=sysDictService.saveOrUpdate(sysDict);
		if(result<=0){
			return new Result().setStatusFail().setMsg(msg+"未成功");
		}
		return new Result().setResult(sysDict).setMsg(msg+"成功");
	}    


}
